#include <bits/stdc++.h>
using namespace std;
const int N = 55;
int n;
int h[N], up[N], down[N], ans;
void dfs(int u, int su, int sd) {
  if (su + sd >= ans) return;
  if (u == n) {
    ans = min(ans, su + sd);
    return;
  }
  int k = 0;
  while (k < su && up[k] >= h[u]) k++;
  if (k < su) {
    int t = up[k];
    up[k] = h[u];
    dfs(u + 1, su, sd);
    up[k] = t;
  } else {
    up[k] = h[u];
    dfs(u + 1, su + 1, sd);
  }

  int k = 0;
  while (k < sd) {
    int t = down[k];
    down[k] = h[u];
    dfs(u + 1, su, sd);
    down[k] = t;
  }
}
int main() {
  while (cin >> n, n) {
    for (int i = 0; i < n; ++i) cin >> h[i];
    ans = n;
    dfs(0, 0, 0);
    cout << ans << endl;
  }
}
